package com.cakebackoffice;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.cakebackoffice.Model.Store;

import java.util.List;


public class ListViewStoreAdapter extends ArrayAdapter<Store> {
    int resource;

    public ListViewStoreAdapter(Context context, int textViewResourceId, List<Store> stores) {
        super(context, textViewResourceId, stores);
        this.resource = textViewResourceId;
    }

    // On override ArrayAdapter
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LinearLayout objectView;
        // Récuperer l'order courant
        Store store = getItem(position);


        // Inflate the catalog_detail_product
        if (convertView == null) {
            objectView = new LinearLayout(getContext());
            String inflater = Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflater vi = (LayoutInflater) getContext().getSystemService(inflater);
            vi.inflate(resource, objectView, true);
        } else {
            objectView = (LinearLayout) convertView;
        }

        // Récupérer les View des orderView
        TextView listViewText = (TextView) objectView.findViewById(R.id.ListCatalogText);

        listViewText.setText(store.getName());

        return (objectView);


    }


}
